# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Michał Polański <michal@polanski.me>
pkgname=dstask
pkgver=0.26
pkgrel=9
pkgdesc="Personal task tracker designed to help you focus"
url="https://dstask.org/"
license="MIT"
# loongarch64: https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/67841
arch="all !loongarch64"
makedepends="go git"
subpackages="
	$pkgname-import:_import
	$pkgname-bash-completion
	$pkgname-zsh-completion
	"
source="https://github.com/naggie/dstask/archive/v$pkgver/dstask-$pkgver.tar.gz
	integration-tests.patch
	"

export GOFLAGS="$GOFLAGS -trimpath -modcacherw"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	_git_commit=$(zcat "$srcdir"/dstask-$pkgver.tar.gz | git get-tar-commit-id)
	_build_date=$(date -u "+%Y-%m-%dT%TZ" ${SOURCE_DATE_EPOCH:+-d @$SOURCE_DATE_EPOCH})
	_ldflags="
		-X github.com/naggie/dstask.GIT_COMMIT=$_git_commit
		-X github.com/naggie/dstask.VERSION=$pkgver-r$pkgrel
		-X github.com/naggie/dstask.BUILD_DATE=$_build_date
		"

	go build -ldflags="$_ldflags" -v -o bin/dstask ./cmd/dstask
	go build -ldflags="$_ldflags" -v -o bin/dstask-import ./cmd/dstask-import
}

check() {
	# tests try to make git commits and fail when hostname is not an FQDN
	EMAIL="buildozer@alpinelinux.org" go test ./...
}

_import() {
	pkgdesc="Import tool for dstask"
	amove usr/bin/dstask-import
}

package() {
	install -Dm755 bin/dstask "$pkgdir"/usr/bin/dstask
	install -Dm755 bin/dstask-import "$pkgdir"/usr/bin/dstask-import

	install -Dm644 .dstask-bash-completions.sh \
		"$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm644 .dstask-zsh-completions.sh \
		"$pkgdir"/usr/share/zsh/site-functions/_$pkgname
}

sha512sums="
a1c493b9e66ef0a11f6c525aa190eb6f5be91b19d63c6d491b2c972d43e5a82f157f6030cbf8debab92118e574ebc464bc14b7ae40f0381789cfa81fe17f86d6  dstask-0.26.tar.gz
fefaca68b53248f77c09584393bb251af318704f0cf2cc79b927558a587aaaabda4d79c0d88836e1913d2697d2a3744f3fc760ab8ec4d36cb3957b61d9f68b40  integration-tests.patch
"
